﻿using System.ComponentModel;
using StyleMVVM.ViewModel;
using System;
using System.Linq;
using Wala.Connection.Objects.Contacts;
using StyleMVVM.View;
using Wala.Infrastructure;

namespace Wala.ViewModels.Friends
{
    public class FriendDetailPageViewModel : PageViewModel, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        #region //------------- Private Fields ------------//
        
        private ContactBasic profile;

        #endregion

        #region //------------ CLR Properties -------------//

        public ContactBasic Profile
        {
            get { return profile; }
            set
            {
                if (profile != value)
                {
                    profile = value;
                    OnPropertyChanged("Profile");
                }
            }
        }

        public string AvatarLink
        {
            get
            {
                if (profile != null)
                {
                    if (profile.Friend_avatar_id != 0)
                    {
                        return string.Format(URLConstant.GET_AVATAR, profile.Friend_avatar_id);
                    }
                    else
                    { 
                        return "ms-appx:///Assets/Login/icon_logo.png";
                    }
                }
                return "ms-appx:///Assets/Login/icon_logo.png";
            }
        }

        public string DisplayName
        {
            get
            {
                if (profile != null)
                {
                    return profile.Friend_display_name;
                }
                return "";
            }
        }

        public string FriendID
        {
            get
            {
                if (profile != null)
                {
                    return profile.Friend_id.ToString();
                }
                return "";
            }
        }

        public string Gender
        {
            get
            {
                if (profile != null)
                {
                    int gender = profile.Gender;
                    if (gender == Constants.Gender.GENDER_FEMALE)
                    {
                        return "Female";
                    }
                    if (gender == Constants.Gender.GENDER_MALE)
                    {
                        return "Male";
                    }
                    if (gender == Constants.Gender.GENDER_UNDEFINED)
                    {
                        return "Hi-fi";
                    }
                        
                }
                return "";
            }
        }    

        #endregion

        #region //--------- Override Methods ------------//

        protected override void OnNavigatedTo(object sender, StyleNavigationEventArgs e)
        {
            profile = NavigationParameter as ContactBasic;
        }
        #endregion

        #region //----------- Protected Methods ----------//

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
